package main

import (
	"fmt"
	"log"
	"path/filepath"

	"github.com/sciter-sdk/go-sciter"
	"github.com/sciter-sdk/go-sciter/window"
)

func main() {
	fmt.Println("Hello GO!")
	GL_ := NewGL()

	var v11 interface{} = GL_
	var v21 Object = GL_
	fmt.Println("v1:", v11, v21, v21.id())

	ret, suc := MethodCall(GL_, "Test1")
	fmt.Println(ret)
	fmt.Println(suc)

	ret1, suc1 := MethodCallByID(2, "Test1")
	fmt.Println(ret1)
	fmt.Println(suc1)

	fmt.Println("Hello GoCall!")
	v1 := sciter.NewValue(int64(GL_.m_id))
	v2 := sciter.NewValue("Test1")

	v3 := GoCall(v1, v2)
	fmt.Println("v3:", v3)

	w, err := window.New(sciter.SW_TITLEBAR|sciter.SW_RESIZEABLE|sciter.SW_CONTROLS|sciter.SW_MAIN|sciter.SW_ENABLE_DEBUG, nil)
	if err != nil {
		log.Fatal("Create Window Error: ", err)
	}
	fullpath, err := filepath.Abs("simple.html")
	if err != nil {
		log.Fatal(err)
	}

	w.DefineFunction("GoCall", GoCall)

	w.LoadFile(fullpath)

	w.Call("XXX")
	w.Call("TrySome")

	w.Show()
	w.Run()
}

/*
func main() {
	w, err := window.New(sciter.SW_TITLEBAR|sciter.SW_RESIZEABLE|sciter.SW_CONTROLS|sciter.SW_MAIN|sciter.SW_ENABLE_DEBUG, nil)
	if err != nil {
		log.Fatal("Create Window Error: ", err)
	}
	fullpath, err := filepath.Abs("simple.html")
	if err != nil {
		log.Fatal(err)
	}

	w.DefineFunction("kkk", func(args ...*sciter.Value) *sciter.Value {
		log.Println("kkk called!")
		rval := sciter.NewValue()
		rval.Set("num", sciter.NewValue(1000))
		rval.Set("str", sciter.NewValue("a string"))
		var fn sciter.NativeFunctor
		fn = func(args ...*sciter.Value) *sciter.Value {
			log.Printf("args[%d]:%v\n", len(args), args)
			return sciter.NewValue("native functor called")
		}
		rval.Set("f", sciter.NewValue(fn))
		return rval
	})

	w.LoadFile(fullpath)
	w.Show()
	w.Run()
}
*/
